/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DensityPanel.java
 *
 * Created on 7-okt-2009, 20:37:40
 */
package gui;

import flowvis.ColorMap;
import flowvis.DensityRenderer;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
 *
 * @author michel
 */
public class DensityRendererPanel extends javax.swing.JPanel {

    private static DensityRenderer densityRenderer;
    // Color legend: starting point, width, height and space between values.
    private static int xi = 20, yi=80, w = 30, h=256, dt=20;
    private static int l, dy, dt1, dt2;
    private static Font font = new Font("Serif", Font.PLAIN, 12);
    private static float values[];

    /** Creates new form DensityPanel */
    public DensityRendererPanel(DensityRenderer renderer) {
        initComponents();
        densityRenderer = renderer;
        coloringCombobox.setSelectedIndex(renderer.getColoring());
    }
    /**
     * @param nv , number of values.
     */
    private static void paintValues( int nv, Graphics2D g2d ){
        values = new float[nv];
        values[0] = (float)DensityRenderer.MAX_USER_DENSITY;
        values[nv-1]= (float)DensityRenderer.MIN_USER_DENSITY;
        int i;
        for( i=1;i<nv-1;i++ )
            values[i] = values[i-1]-(float)((DensityRenderer.MAX_USER_DENSITY-DensityRenderer.MIN_USER_DENSITY)/(float)(nv-1));
        // Paint
        dt1=yi+10+l*dy;
        g2d.setFont(font);
        g2d.drawString(String.valueOf(values[nv-1]), xi+w+2, dt1);
        for( i=l-1;i>=0;i-- ){
            dt2=yi+10+i*dy;
            if( dt1-dt2>dt ){
                g2d.drawString(String.valueOf(values[i]), xi+w+2, dt2);
                dt1=dt2;
            }
        }
    }
    
    /**
     * Paint the color legend
     * @param g2d , standard Java2D drawing object.
     * @param colorMap to use.
     */
    private static void paintColorLegend( Graphics2D g2d, int colorMap ){
        // color and value to create the l colors.
        float rgb[] = new float[3], v;
        // Obtain the height of the color box
        dy = (int)Math.ceil(h/(l+1));
        // Obtain the values and paint some of them
        paintValues( (int)Math.ceil(256/dy), g2d );
        // Paint colors
        for( int i=l;i>=0;i-- ){
            // From v, obtain the rgb color
            v=1.0f-((float)i/((float)(l)));
            switch( colorMap ){
                case ColorMap.COLOR_BLACKWHITE:
                case ColorMap.COLOR_BLACKWHITE_BANDS:
                    ColorMap.blackwhite(v, rgb, DensityRenderer.withHue(), DensityRenderer.withSaturation() );
                    break;
                case ColorMap.COLOR_RAINBOW:
                case ColorMap.COLOR_RAINBOW_BANDS:
                    ColorMap.rainbow(v, rgb, DensityRenderer.withHue(), DensityRenderer.withSaturation() );
                    break;
                case ColorMap.COLOR_BLACKBODY:
                case ColorMap.COLOR_BLACKBODY_BANDS:
                    ColorMap.blackbody(v, rgb, DensityRenderer.withHue(), DensityRenderer.withSaturation() );
                    break;
                case ColorMap.COLOR_TEMPERATURE:
                case ColorMap.COLOR_TEMPERATURE_BANDS:
                    ColorMap.temperature(v, rgb, DensityRenderer.withHue(), DensityRenderer.withSaturation() );
                    break;
                case ColorMap.COLOR_GRADIENT_G2R:
                case ColorMap.COLOR_GRADIENT_G2R_BANDS:
                    ColorMap.green2red(v, rgb, DensityRenderer.withHue(), DensityRenderer.withSaturation() );
                    break;
            }
            g2d.setPaint( new Color(rgb[0],rgb[1],rgb[2]) );
            g2d.fillRect(xi, yi-1+i*dy, w, dy);
        }
    }

    /**
     * Painting of color legend.
     */
    @Override public void paintComponent( Graphics g ){
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;

        switch( densityRenderer.getColoring() ){
            case ColorMap.COLOR_BLACKWHITE:
                l = 255;
                nLevelsString.setVisible( false );
                nLevels.setVisible( false );
                paintColorLegend(g2d, ColorMap.COLOR_BLACKWHITE);
                break;
            case ColorMap.COLOR_BLACKWHITE_BANDS:
                l = densityRenderer.getNLevels();
                nLevelsString.setText(String.valueOf(l+1));
                nLevelsString.setVisible( true );
                nLevels.setVisible( true );
                paintColorLegend(g2d, ColorMap.COLOR_BLACKWHITE_BANDS);
                break;
            case ColorMap.COLOR_RAINBOW:
                l=255;
                nLevelsString.setVisible( false );
                nLevels.setVisible( false );
                paintColorLegend(g2d, ColorMap.COLOR_RAINBOW);
                break;
            case ColorMap.COLOR_RAINBOW_BANDS:
                l = densityRenderer.getNLevels();
                nLevelsString.setText(String.valueOf(l+1));
                nLevelsString.setVisible( true );
                nLevels.setVisible( true );
                paintColorLegend(g2d, ColorMap.COLOR_RAINBOW_BANDS);
                break;
            case ColorMap.COLOR_BLACKBODY:
                l=255;
                nLevelsString.setVisible( false );
                nLevels.setVisible( false );
                paintColorLegend(g2d, ColorMap.COLOR_BLACKBODY);
                break;
            case ColorMap.COLOR_BLACKBODY_BANDS:
                l = densityRenderer.getNLevels();
                nLevelsString.setText(String.valueOf(l+1));
                nLevelsString.setVisible( true );
                nLevels.setVisible( true );
                paintColorLegend(g2d, ColorMap.COLOR_BLACKBODY_BANDS);
                break;
            case ColorMap.COLOR_TEMPERATURE:
                l=255;
                nLevelsString.setVisible( false );
                nLevels.setVisible( false );
                paintColorLegend(g2d, ColorMap.COLOR_TEMPERATURE);
                break;
            case ColorMap.COLOR_TEMPERATURE_BANDS:
                l = densityRenderer.getNLevels();
                nLevelsString.setText(String.valueOf(l+1));
                nLevelsString.setVisible( true );
                nLevels.setVisible( true );
                paintColorLegend(g2d, ColorMap.COLOR_TEMPERATURE_BANDS);
                break;
            case ColorMap.COLOR_GRADIENT_G2R:
                l=255;
                nLevelsString.setVisible( false );
                nLevels.setVisible( false );
                paintColorLegend(g2d, ColorMap.COLOR_GRADIENT_G2R);
                break;
            case ColorMap.COLOR_GRADIENT_G2R_BANDS:
                l = densityRenderer.getNLevels();
                nLevelsString.setText(String.valueOf(l+1));
                nLevelsString.setVisible( true );
                nLevels.setVisible( true );
                paintColorLegend(g2d, ColorMap.COLOR_GRADIENT_G2R_BANDS);
                break;
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        coloringCombobox = new javax.swing.JComboBox();
        nLevels = new javax.swing.JSlider();
        nLevelsString = new javax.swing.JTextField();
        useHue = new javax.swing.JCheckBox();
        useSaturation = new javax.swing.JCheckBox();
        maxValueSlider = new javax.swing.JSlider();
        maxValueText = new javax.swing.JTextField();
        minValueSlider = new javax.swing.JSlider();
        minValueText = new javax.swing.JTextField();
        saturationLabel = new javax.swing.JLabel();
        saturationSlider = new javax.swing.JSlider();
        saturationTextField = new javax.swing.JTextField();
        hueTextField = new javax.swing.JTextField();
        hueSlider = new javax.swing.JSlider();
        hueLabel = new javax.swing.JLabel();

        coloringCombobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Grey scale", "Grey scale (banded)", "Rainbow", "Rainbow (banded)", "Black body", "Black body (banded)", "Temperature", "Temperature (banded)", "Green to Red", "Green to Red (banded)" }));
        coloringCombobox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                coloringComboboxActionPerformed(evt);
            }
        });

        nLevels.setMaximum(256);
        nLevels.setMinimum(2);
        nLevels.setToolTipText("Amount of colors (for banded color maps)");
        nLevels.setValue(128);
        nLevels.setName("nLevels"); // NOI18N
        nLevels.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                nLevelsMouseReleased(evt);
            }
        });
        nLevels.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                nLevelsDragged(evt);
            }
        });
        nLevels.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                nLevelsKeyReleased(evt);
            }
        });

        nLevelsString.setEditable(false);
        nLevelsString.setToolTipText("Number of colors");

        useHue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useHueActionPerformed(evt);
            }
        });

        useSaturation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useSaturationActionPerformed(evt);
            }
        });

        maxValueSlider.setMaximum(100000);
        maxValueSlider.setMinimum(1);
        maxValueSlider.setValue(10000);
        maxValueSlider.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                maxValueSliderMouseReleased(evt);
            }
        });
        maxValueSlider.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                maxValueSliderMouseDragged(evt);
            }
        });
        maxValueSlider.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                maxValueSliderKeyReleased(evt);
            }
        });

        maxValueText.setEditable(false);
        maxValueText.setText("MAX: "+String.valueOf(DensityRenderer.MAX_USER_DENSITY));
        maxValueText.setToolTipText("Maximum density magnitude");

        minValueSlider.setMaximum(99999);
        minValueSlider.setValue(0);
        minValueSlider.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                minValueSliderMouseReleased(evt);
            }
        });
        minValueSlider.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                minValueSliderMouseDragged(evt);
            }
        });
        minValueSlider.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                minValueSliderKeyReleased(evt);
            }
        });

        minValueText.setEditable(false);
        minValueText.setText("MIN: "+String.valueOf(DensityRenderer.MIN_USER_DENSITY));
        minValueText.setToolTipText("Minimum density value");

        saturationLabel.setText("Saturation :");
        saturationLabel.setName("Saturation"); // NOI18N

        saturationSlider.setToolTipText("Drag to change the value of the saturation");
        saturationSlider.setValue(0);
        saturationSlider.setName("saturationSlide"); // NOI18N
        saturationSlider.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                saturationSliderMouseDragged(evt);
            }
        });

        saturationTextField.setEditable(false);
        saturationTextField.setName("saturationTextField"); // NOI18N

        hueTextField.setEditable(false);
        hueTextField.setName("hueTextField"); // NOI18N

        hueSlider.setMaximum(360);
        hueSlider.setToolTipText("Drag to change the value of the hue");
        hueSlider.setValue(0);
        hueSlider.setName("hueSlide"); // NOI18N
        hueSlider.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                hueSliderMouseDragged(evt);
            }
        });

        hueLabel.setText("Hue :");
        hueLabel.setName("Time_Step"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(191, 191, 191)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(coloringCombobox, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(nLevelsString, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nLevels, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(12, 12, 12))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(169, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(maxValueSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(8, 8, 8))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(minValueText, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(28, 28, 28)
                            .addComponent(maxValueText, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(minValueSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(9, 9, 9)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(useSaturation)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(saturationLabel))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(useHue)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(hueLabel)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(hueSlider, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                            .addComponent(hueTextField)
                            .addComponent(saturationTextField, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(saturationSlider, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(nLevelsString, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(coloringCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(nLevels, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(useSaturation)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(saturationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(saturationLabel))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(saturationSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(hueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(hueLabel)))
                    .addComponent(useHue))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(hueSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 118, Short.MAX_VALUE)
                .addComponent(maxValueSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxValueText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(minValueText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(minValueSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(97, 97, 97))
        );

        useHue.getAccessibleContext().setAccessibleName("useHue");
        useSaturation.getAccessibleContext().setAccessibleName("useSaturation");
    }// </editor-fold>//GEN-END:initComponents

    private void coloringComboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_coloringComboboxActionPerformed
        densityRenderer.setColoring(coloringCombobox.getSelectedIndex());
        this.updateUI();
    }//GEN-LAST:event_coloringComboboxActionPerformed

    private void nLevelsKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nLevelsKeyReleased
        densityRenderer.setNLevels(nLevels.getValue() - 1);
        this.updateUI();
    }//GEN-LAST:event_nLevelsKeyReleased

    private void nLevelsDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nLevelsDragged
        densityRenderer.setNLevels(nLevels.getValue() - 1);
        nLevelsString.setText(String.valueOf(densityRenderer.getNLevels()+1));
    }//GEN-LAST:event_nLevelsDragged

    private void useHueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useHueActionPerformed
        DensityRenderer.useHue( useHue.isSelected() );
        this.updateUI();
    }//GEN-LAST:event_useHueActionPerformed

    private void useSaturationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useSaturationActionPerformed
        DensityRenderer.useSaturation( useSaturation.isSelected() );
        this.updateUI();
    }//GEN-LAST:event_useSaturationActionPerformed

    private void maxValueSliderMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_maxValueSliderMouseDragged
        DensityRenderer.MAX_USER_DENSITY=((float)maxValueSlider.getValue())/10000.0f;
        maxValueText.setText("MAX: "+String.valueOf(DensityRenderer.MAX_USER_DENSITY));
    }//GEN-LAST:event_maxValueSliderMouseDragged

    private void maxValueSliderMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_maxValueSliderMouseReleased
        this.updateUI();
    }//GEN-LAST:event_maxValueSliderMouseReleased

    private void nLevelsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nLevelsMouseReleased
        this.updateUI();
    }//GEN-LAST:event_nLevelsMouseReleased

    private void maxValueSliderKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_maxValueSliderKeyReleased
        DensityRenderer.MAX_USER_DENSITY=((float)maxValueSlider.getValue())/10000.0f;
        maxValueText.setText("MAX: "+String.valueOf(DensityRenderer.MAX_USER_DENSITY));
        this.updateUI();
    }//GEN-LAST:event_maxValueSliderKeyReleased

    private void minValueSliderMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_minValueSliderMouseReleased
        this.updateUI();
    }//GEN-LAST:event_minValueSliderMouseReleased

    private void minValueSliderMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_minValueSliderMouseDragged
        DensityRenderer.MIN_USER_DENSITY=((float)minValueSlider.getValue())/10000.0f;
        minValueText.setText("MIN: "+String.valueOf(DensityRenderer.MIN_USER_DENSITY));
    }//GEN-LAST:event_minValueSliderMouseDragged

    private void minValueSliderKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_minValueSliderKeyReleased
        DensityRenderer.MIN_USER_DENSITY=((float)minValueSlider.getValue())/10000.0f;
        minValueText.setText("MIN: "+String.valueOf(DensityRenderer.MIN_USER_DENSITY));
        this.updateUI();
    }//GEN-LAST:event_minValueSliderKeyReleased

    private void saturationSliderMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saturationSliderMouseDragged
        float s = (float) saturationSlider.getValue();
        saturationTextField.setText(String.valueOf(s) + "%");
        ColorMap.setSaturation((float) s);   
        FlowSimulatorPanel.saturationSlider.setValue(saturationSlider.getValue());
        FlowSimulatorPanel.saturationTextField.setText(saturationTextField.getText());
        ForceRendererPanel.saturationSlider.setValue(saturationSlider.getValue());
        ForceRendererPanel.saturationTextField.setText(saturationTextField.getText());
        VelocityRendererPanel.saturationSlider.setValue(saturationSlider.getValue());
        VelocityRendererPanel.saturationTextField.setText(saturationTextField.getText());
        DivergenceRendererPanel.saturationSlider.setValue(saturationSlider.getValue());
        DivergenceRendererPanel.saturationTextField.setText(saturationTextField.getText());
        IsoLinesRendererPanel.saturationSlider.setValue(saturationSlider.getValue());
        IsoLinesRendererPanel.saturationTextField.setText(saturationTextField.getText());
        this.updateUI();
    }//GEN-LAST:event_saturationSliderMouseDragged

    private void hueSliderMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_hueSliderMouseDragged
        float h = (float) hueSlider.getValue();
        hueTextField.setText(String.valueOf(h) + " degrees");
        ColorMap.setHue((float) h);
        FlowSimulatorPanel.hueSlider.setValue(hueSlider.getValue());
        FlowSimulatorPanel.hueTextField.setText(hueTextField.getText());
        ForceRendererPanel.hueSlider.setValue(hueSlider.getValue());
        ForceRendererPanel.hueTextField.setText(hueTextField.getText());
        VelocityRendererPanel.hueSlider.setValue(hueSlider.getValue());
        VelocityRendererPanel.hueTextField.setText(hueTextField.getText());
        DivergenceRendererPanel.hueSlider.setValue(hueSlider.getValue());
        DivergenceRendererPanel.hueTextField.setText(hueTextField.getText());
        IsoLinesRendererPanel.hueSlider.setValue(hueSlider.getValue());
        IsoLinesRendererPanel.hueTextField.setText(hueTextField.getText());
        this.updateUI();
    }//GEN-LAST:event_hueSliderMouseDragged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox coloringCombobox;
    private javax.swing.JLabel hueLabel;
    public static javax.swing.JSlider hueSlider;
    public static javax.swing.JTextField hueTextField;
    private javax.swing.JSlider maxValueSlider;
    private javax.swing.JTextField maxValueText;
    private javax.swing.JSlider minValueSlider;
    private javax.swing.JTextField minValueText;
    private javax.swing.JSlider nLevels;
    private javax.swing.JTextField nLevelsString;
    private javax.swing.JLabel saturationLabel;
    public static javax.swing.JSlider saturationSlider;
    public static javax.swing.JTextField saturationTextField;
    private javax.swing.JCheckBox useHue;
    private javax.swing.JCheckBox useSaturation;
    // End of variables declaration//GEN-END:variables
}
